<template >
  <div class="personal">
    <router-link :to="'/editUserInfo/' + $route.params.id">
      <div class="profile">
        <img :src="current.head_img" alt />
        <div class="profile-center">
          <div class="name">
            <span
              class="iconfont"
              :class="{
                iconxingbienan: current.gender == 1,
                iconxingbienv: current.gender == 0,
                span: !current.gender,
              }"
            ></span
            >{{ current.nickname }}
          </div>
          <div class="time">{{ current.create_date | dateFormat }}</div>
        </div>
        <span class="iconfont iconjiantou1"></span>
      </div>
    </router-link>
    <hmcell
      title="我的关注"
      desc="关注的用户"
      @click="$router.push({ name: 'follows' })"
    >
    </hmcell>
    <hmcell title="我的跟帖" desc="跟帖/回复"> </hmcell>
    <hmcell
      title="我的收藏"
      desc="文章/视频"
      @click="$router.push({ name: 'mysatr' })"
    >
    </hmcell>
    <hmcell title="设置"> </hmcell>

    <hmbutton type="danger" @click="exit">退出</hmbutton>
  </div>
</template>

<script>
import hmbutton from "@/components/hmbutton";
// 引入块封装组件
import hmcell from "@/components/hmcell";
//获取个人中心数据
import { edit_profile } from "@/apis/user";
// 引入过滤器
import { dateFormat } from "@/utils/filters";
//引入请求组件
import axios from "@/utils/myaxios";
export default {
  data() {
    return {
      current: {},
    };
  },
  methods: {
    //退出
    exit() {
      // console.log(1)
      // 删除缓存
      localStorage.removeItem("toutiao_59_token");
      localStorage.removeItem("toutiao_59");
      localStorage.removeItem("toutiao_59_id");
      // 跳转路由到首页
      this.$router.push({ name: "default" });
    },
  },
  // 注册组件
  components: {
    hmcell,
    hmbutton,
  },
  // 过滤器
  filters: {
    dateFormat,
  },
  async mounted() {
    console.log(this.$route.params.id);
    let id = this.$route.params.id;
    // 请求用户详情
    let res = await edit_profile(id);
    console.log(res);
    if (res.data.message == "获取成功") {
      // 渲染之前，对数据进行改造
      res.data.data.head_img = axios.defaults.baseURL + res.data.data.head_img;

      this.current = res.data.data;
    }
  },
};
</script>

<style lang='less' scoped>
/deep/.btn {
  margin: 10px auto;
}
.personal {
  width: 100vw;
  height: 100vh;
  background-color: #eee;
}
a {
  color: #666;
}
.profile {
  display: flex;
  padding: 20px 10px;
  justify-content: space-between;
  align-items: center;
  border-bottom: 5px #ddd solid;

  img {
    width: 70 / 360 * 100vw;
    height: 70 / 360 * 100vw;
    border-radius: 50%;
  }

  .profile-center {
    flex: 1;
    padding: 0 10px;
  }

  .name {
    .span {
      color: rgba(231, 18, 117, 0.747);
    }
    span {
      color: #75b9eb;
    }
  }

  .time {
    color: #666;
    font-size: 14px;
    margin-top: 5px;
  }
}
</style>